﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YTSK.Model;

namespace YTSK.cSK.UKey
{
    class Swith
    {
        public static string proc(FpType cbilltype, Model.SK_SalebillVouch sk,
            List<Model.SK_SalebillVouchs_View> l_sks,
            out string fpdm, out string fphm)
        {
            var err = "";
            var maxmoney = cSKSet.GetMaxMoney(cbilltype);
            var fpmoney = l_sks.Sum(s => s.iSumSale.ObjToDecimal());
            if (fpmoney > maxmoney)
            {
                err = string.Format("[{0}]发票金额[{1}]大于税控机最大开票限额[{2}]", cbilltype, fpmoney, maxmoney);
                fpdm = "";
                fphm = "";
                return err;
            }

            string filename;
            string str_xml;
            switch (cbilltype)
            {
                case FpType.纸质专用发票:
                    err = cMakeXML.ZP(sk, l_sks, out filename);
                    err += cKP_ZP.proc(filename, out fpdm, out fphm);
                    break;
                case FpType.纸质普通发票:
                    err = cMakeXML.ZP(sk, l_sks, out filename);
                    err += cKP_PP.proc(filename, out fpdm, out fphm);
                    break;
                case FpType.电子普通发票:
                    err = cSK.cMakeXML.DZP_Ukey(sk, l_sks, out filename,out str_xml);
                    err += cKP_DZP.proc(sk,filename, out fpdm, out fphm, str_xml);
                    break;
                case FpType.电子专用发票:
                    err = cSK.cMakeXML.DZP_Ukey(sk, l_sks, out filename,out str_xml);
                    err += cKP_DZP.proc(sk,filename, out fpdm, out fphm, str_xml);
                    break;
                default:
                    err = "此单设置了[不开票]";
                    fpdm = "";
                    fphm = "";
                    break;
            }

            return err;
        }
    }
}